/*
 * @(#)XIndentIcon.java        1.0 2000/05/09
 *
 * This file is part of Xfuzzy 3.0, a design environment for fuzzy logic
 * based systems.
 *
 * (c) 2000 IMSE-CNM. The authors may be contacted by the email address:
 *                    xfuzzy-team@imse.cnm.es
 *
 * Xfuzzy is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by
 * the Free Software Foundation.
 *
 * Xfuzzy is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * for more details.
 */

package xfuzzy.util;

import javax.swing.*;
import java.awt.*;
import java.io.File;

/**
 * Icono dibujado con un desplazamiento
 * 
 * @author Francisco Jos� Moreno Velo
 */
public class XIndentIcon implements Icon {

	//----------------------------------------------------------------------------//
	//                            MIEMBROS PRIVADOS                               //
	//----------------------------------------------------------------------------//

	/**
	 * Icono a dibujar desplazado
	 */
	private Icon icon = null;
	
	/**
	 * Nivel de profundidad del icono desplazado
	 */
	private int depth = 0;
	
	/**
	 * Desplazamiento por cada nivel de profundidad
	 */
	private final int space = 10;

	//----------------------------------------------------------------------------//
	//                                CONSTRUCTOR                                 //
	//----------------------------------------------------------------------------//

	/**
	 * Constructor
	 */
	public XIndentIcon(File file, Icon icon) {
		this.icon = icon;
		this.depth = 0;
		File f = file;
		while( f != null && f.getParentFile() != null) {
			this.depth++;
			f = f.getParentFile();
		}
	}

	//----------------------------------------------------------------------------//
	//                             M�TODOS P�BLICOS                               //
	//----------------------------------------------------------------------------//

	/**
	 * Dibuja el icono
	 */
	public void paintIcon(Component c, Graphics g, int x, int y) {
		icon.paintIcon(c, g, x+depth*space, y);
	}

	/**
	 * Devuelve la anchura del icono
	 */
	public int getIconWidth() {
		return icon.getIconWidth() + depth*space;
	}

	/**
	 * Devuelve la altura del icono
	 */
	public int getIconHeight() {
		return icon.getIconHeight();
	}
}

